package com.example.XqmZsb.utils;

//import java.io.Serializable;

import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {
    private static final long serialVersionUID = 4L;
    private Integer code;
    private String message;
    private Long timestamp = System.currentTimeMillis();
    private T data;


    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> resultData = new BaseResponse<>();
        resultData.setCode(200);
        resultData.setMessage("OK");
        resultData.setData(data);
        return resultData;
    }

    public static BaseResponse error(ErrorCode errorCode) {
        BaseResponse resultData = new BaseResponse();
        resultData.setCode(errorCode.getCode());
        resultData.setMessage(errorCode.getMessage());
        return resultData;
    }
}
